{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "179af0a2",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-11-8\n",
    "* 课程：python语言\n",
    "* week08（上课周）\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1daaab5",
   "metadata": {},
   "source": [
    "# 1.本周内容\n",
    "\n",
    "## 1.列表的数据处理（列表的方法）\n",
    "> 1. 查询数据\n",
    ">> 1. index()按照索引值查询数据，并取出值\n",
    ">> 2. slice切片方法取值\n",
    ">> 3. in方法查询元素是否存在\n",
    "> 2. 数据增加\n",
    ">> 1. append()增加在末尾\n",
    ">> 2. insert()指定位置增加\n",
    "> 3. 删除数据\n",
    ">> 1. pop()指定位置删除\n",
    ">> 2. remove()指定结果（值）删除\n",
    ">> 3. clear()清空列表\n",
    "> 4. 修改数据\n",
    ">> 1. 找到index进行修改\n",
    "> 5. 其他\n",
    ">> 1. 排序：sort() reverse()\n",
    ">> 2. 复制：copy()\n",
    "\n",
    "## 2. 元组\n",
    "\n",
    "## 3.列表实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa5ce6bb",
   "metadata": {},
   "source": [
    "## 1.1.列表的删除\n",
    "\n",
    "> 1. pop()\n",
    ">> 1. 默认删除列表中最后一位数据\n",
    ">> 2. 指定位置进行删除\n",
    ">> 3. 注意事项：避免indexerror的出现，先检查列表长度\n",
    "> 2. remove()\n",
    ">> 1. 指定结果（值）删除\n",
    ">> 3. 注意事项：避免valueerror的出现，先检查元素是否存在in\n",
    "> 3. clear()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d475954",
   "metadata": {},
   "source": [
    "## 1. pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "953257bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['扎里苏', '萧逸', '奇斯利', '下明星']\n"
     ]
    }
   ],
   "source": [
    "name_list = [\"扎里苏\",\"萧逸\",\"奇斯利\",\"下明星\"]\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "38ec1382",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'heip' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m heip(name_list)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'heip' is not defined"
     ]
    }
   ],
   "source": [
    "heip(name_list.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f980b5e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'下明星'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9f85be06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "dc02c846",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'萧逸'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b3aac3f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '奇斯利']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46d32ee0",
   "metadata": {},
   "source": [
    "## 2. remove()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "dee19eb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['扎里苏', '萧逸', '奇斯利', '奇斯利', '下明星']\n"
     ]
    }
   ],
   "source": [
    "name_list = [\"扎里苏\",\"萧逸\",\"奇斯利\",\"奇斯利\",\"下明星\"]\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8bbc4977",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['扎里苏', '萧逸', '奇斯利', '下明星']\n"
     ]
    }
   ],
   "source": [
    "name_list.remove(\"奇斯利\")\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4b7cb91c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 先查询是否存在该值\n",
    "\"hhh\"in name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1466370a",
   "metadata": {},
   "source": [
    "## 3. clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "44a2378f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['扎里苏', '萧逸', '奇斯利', '奇斯利', '下明星']\n"
     ]
    }
   ],
   "source": [
    "name_list = [\"扎里苏\",\"萧逸\",\"奇斯利\",\"奇斯利\",\"下明星\"]\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "a193d904",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "0e2ac952",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6307a3b5",
   "metadata": {},
   "source": [
    "## 1. 排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "9a4d00a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[17, 13, 15, 16, 18, 22, 21]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list = [17,13,15,16,18,22,21]\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "284050ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e748ec6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[13, 15, 16, 17, 18, 21, 22]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "106ba566",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "8fc15406",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[22, 21, 18, 17, 16, 15, 13]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc061463",
   "metadata": {},
   "source": [
    "## 2. 复制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "b84f27b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['扎里苏', '萧逸', '奇斯利', '下明星']\n"
     ]
    }
   ],
   "source": [
    "name_list = [\"扎里苏\",\"萧逸\",\"奇斯利\",\"下明星\"]\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "e4f37b5b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利', '下明星']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "存档_name_list = name_list\n",
    "存档_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "1c8f37f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list.append(\"charlie\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "451a510c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利', '下明星', 'charlie']"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "f609af74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利', '下明星', 'charlie']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "存档_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "9a44d687",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['扎里苏', '萧逸', '奇斯利', '下明星']\n"
     ]
    }
   ],
   "source": [
    "# 综上，并不能真正地复制，看一下copy\n",
    "name_list = [\"扎里苏\",\"萧逸\",\"奇斯利\",\"下明星\"]\n",
    "print(name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "659d24e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利', '下明星']"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "copy_name_list = name_list.copy()\n",
    "copy_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "7d9d956e",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list.append(\"charlie\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "4878b493",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利', '下明星', 'charlie']"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "99eb4f68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['扎里苏', '萧逸', '奇斯利', '下明星']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "copy_name_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c945fe4e",
   "metadata": {},
   "source": [
    "## 2. 元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "108cc057",
   "metadata": {},
   "outputs": [],
   "source": [
    "t = 12345,23455,\"hello\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "944f5c4d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(12345, 23455, 'hello')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(t)\n",
    "print(type(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "314fb6bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(12345, 23455, 'hello')"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = 12345,23455,\"hello\"\n",
    "t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "6f581d32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12345"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "93598833",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(12345, 23455)"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "5f025a49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.index(12345)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "4162b2da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.count(12345)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "42144a22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2023, tm_mon=11, tm_mday=8, tm_hour=11, tm_min=32, tm_sec=46, tm_wday=2, tm_yday=312, tm_isdst=0)"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 案例\n",
    "import time\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "07f9fcb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1699414381.679717"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00466884",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
